cmake_minimum_required(VERSION 3.5)

project(QxFrameless LANGUAGES CXX VERSION ${QX_FRAMELESS_VERSION})
set(QX_FRAMELESS_MODULE_NAME qxframeless)
set(QX_FRAMELESS_LIB_NAME ${QX_FRAMELESS_MODULE_NAME}${PROJECT_VERSION_MAJOR})

set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)

if(QX_FRAMELESS_CONFIG_BUILD_STATIC)
    add_definitions(-DQX_FRAMELESS_LIBRARY_STATIC)
    set(QX_FRAMELESS_LIB_TYPE "STATIC")
else()
    add_definitions(-DQX_FRAMELESS_LIBRARY)
    set(QX_FRAMELESS_LIB_TYPE "SHARED")
endif()

if(QX_FRAMELESS_CONFIG_NATIVE)
    add_definitions(-DQX_FRAMELESS_NATIVE)
endif()

set(QX_FRAMELESS_PUBLIC_HEADERS
    qxframeless_global.h
    framelesshelper.h
)

set(QX_FRAMELESS_PRIVATE_HEADERS
    framelesshelper_p.h
)

set(QX_FRAMELESS_SOURCES
    framelesshelper.cpp
)

add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

add_library(${QX_FRAMELESS_LIB_NAME} ${QX_FRAMELESS_LIB_TYPE}
    ${QX_FRAMELESS_PUBLIC_HEADERS}
    ${QX_FRAMELESS_PRIVATE_HEADERS}
    ${QX_FRAMELESS_SOURCES}
)

target_include_directories(${QX_FRAMELESS_LIB_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(${QX_FRAMELESS_LIB_NAME} PUBLIC
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::Gui
    Qt${QT_VERSION_MAJOR}::Widgets
)

set_target_properties(${QX_FRAMELESS_LIB_NAME} PROPERTIES
   AUTOMOC ON
   AUTOUIC ON
   AUTORCC ON
   CXX_EXTENSIONS OFF
   VERSION ${QX_FRAMELESS_VERSION}
   EXPORT_NAME ${QX_FRAMELESS_LIB_NAME}
   ARCHIVE_OUTPUT_DIRECTORY "${QX_FRAMELESS_BIN_DIR}/lib"
   LIBRARY_OUTPUT_DIRECTORY "${QX_FRAMELESS_BIN_DIR}/lib"
   RUNTIME_OUTPUT_DIRECTORY "${QX_FRAMELESS_BIN_DIR}/bin"
)

install(FILES ${QX_FRAMELESS_PUBLIC_HEADERS}
    DESTINATION include/${QX_FRAMELESS_MODULE_NAME}
    COMPONENT headers
)

install(FILES
    "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE"
    DESTINATION license/${QX_FRAMELESS_MODULE_NAME}
    COMPONENT license
)

install(TARGETS ${QX_FRAMELESS_LIB_NAME}
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    INCLUDES DESTINATION include/${QX_FRAMELESS_MODULE_NAME}
)

target_include_directories(${QX_FRAMELESS_LIB_NAME} PUBLIC
    $<INSTALL_INTERFACE:include>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
